<template>
  <!-- 招聘信息显示 -->
  <div class="buttons">
    <el-button-group
      v-for="interview in interviewData"
      :key="interview.name"
      style="margin-bottom: 10px"
    >
      <el-button
        type="primary"
        size="large"
        color="#7f96ab"
        style="color: white"
        >{{ interview.name }}---{{ interview.recruit }}
      </el-button>
      <el-button
        type="primary"
        size="large"
        @click="failedInterview(interview)"
      >
        <el-icon class="el-icon-close"><Close /></el-icon>
      </el-button>
      <el-button
        type="primary"
        size="large"
        @click="passedInterview(interview)"
      >
        <el-icon class="el-icon-check"><Check /></el-icon>
      </el-button>
      <el-tag
        :type="
          interview.iflag === 1
            ? 'success'
            : interview.iflag === 2
              ? 'danger'
              : 'info'
        "
      >
        {{
          interview.iflag === 1
            ? '通过'
            : interview.iflag === 2
              ? '未通过'
              : '待定'
        }}
      </el-tag>
    </el-button-group>
  </div>
</template>

<script setup>
import { defineProps, ref, watchEffect } from 'vue'
import { resumeEdit } from '../../../api/hire'
import { Close, Check } from '@element-plus/icons-vue'
// 定义接收父级传递的 props
const props = defineProps({
  dataCheck: Array,
  dataAll: Array
  // visibleDrawerHire: Boolean
})
// 接受传过来的面试数据--分页的数据
const interviewData = ref([])

//所有数据
// const dataAll = props.dataAll
watchEffect(() => {
  // 在 props.dataCheck 变化时被调用
  interviewData.value = props.dataCheck
  // if (dataAll.value) {
  //   interviewData.value = dataAll.value.slice(0, 5)
  // }
})

// 通过简历筛选函数
const passedInterview = async (interview) => {
  interview.iflag = 1
  const res = await resumeEdit(interview)
  if (res.code === 200) {
    ElMessage.success('面试通过')
  }
}

//未通过简历筛选函数
const failedInterview = async (interview) => {
  interview.iflag = 2
  const res = await resumeEdit(interview)
  if (res.code === 200) {
    ElMessage.success('面试未通过')
  }
}
</script>
<style lang="less" scoped>
.buttons {
  display: flex;
  flex-direction: column;
  align-items: center;
  //   width: 100%;

  .el-button-group {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .el-button--primary {
    width: 80%;
    margin: 5px 0; /* 按钮间距 */
  }
  /* 第一个按钮占75% */
  .el-button-group > .el-button--primary:first-child {
    flex: 10; /* 75% */
  }

  /* 其他两个按钮平分剩余的25% */
  .el-button-group > .el-button--primary:not(:first-child) {
    flex: 1; /* 25% / 2 = 12.5% */
  }

  .el-tag {
    // flex: 1;
    margin: 1px; /* 移除标签与按钮之间的间距 */
    height: 40px; /* 假设按钮的高度是40px，可以根据实际情况调整 */
    line-height: 40px; /* 使文本垂直居中 */
    display: flex;
    align-items: center;
    justify-content: center;
    width: 50px;
  }
  .el-button-group > :not(:first-child):first-of-type {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }

  .el-button-group > :not(:first-child):last-of-type {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  .el-button-group > :first-child {
    border-top-right-radius: 0;
    border-bottom-right-radius: 0;
  }

  .el-button-group > :last-child {
    border-top-left-radius: 0;
    border-bottom-left-radius: 0;
  }
}
</style>
